class Queue(object):
    def __init__(self, maxsize=16):
        self.max_size = maxsize+1
        self.rear = 0
        self.front = 0
        self.queue = [None] * self.max_size

    def enqueue(self, e):
        # if self.is_full():
        #     self.max_size *= 2
        #     new_stack = [None]*self.max_size
        #     for i in range(self.cur_size):
        #         new_stack[i] = self.stack[i]
        #     self.stack = new_stack
        assert not self.is_full(), "队满"
        self.queue[self.rear] = e
        self.rear = (self.rear + 1) % self.max_size
        return True

    def dequeue(self):
        assert not self.is_empty(), "队空"
        res = self.queue[self.front]
        self.queue[self.front] = None
        self.front = (self.front + 1) % self.max_size
        return res

    def size(self):
        return (self.rear + self.max_size - self.front) % self.max_size

    def is_empty(self):
        if self.rear == self.front:
            return True
        return False

    def is_full(self):
        if (self.rear + 1) % self.max_size == self.front:
            return True
        return False


if __name__ == "__main__":
    st = Queue(3)
    print(st.is_full())
    print(st.is_empty())
    st.enqueue(1)
    print(st.size())
    st.enqueue(2)
    print(st.size())
    st.enqueue(3)
    print(st.size())
    res = st.dequeue()
    print(res)
    print(st.size())



